import 'dotenv/config';
import type { VercelRequest, VercelResponse } from '@vercel/node';
import{LoginCmd} from "../../dto/index";
import { handleException } from '../../util/exception';
import { checkLogin } from '../../service/user/AuthService';
import { errorWithCodeAndMsg, successWithData } from '../../util/result';
import { login } from '../../service/user/UserService';

/**
 * 登录接口
 */
export default async (_req: VercelRequest, _res: VercelResponse) => {
    try {
        checkLogin(_req)
        return _res.status(200).json(errorWithCodeAndMsg(400,"您已经登录过了"));
    } catch (err) {}
    return await handleException(_req,_res,async (request,response) => {
        const cmd : LoginCmd = request.body;
        return response.json(successWithData(await login(cmd)))
    })
}